package com.zzb.framework.frameworkcontroller.interceptor;

import com.zzb.framework.frameworkcontroller.common.FrameworkBaseController;
import com.zzb.framework.role.vo.SysMenuTreeVO;
import com.zzb.framework.role.vo.UserLoginVo;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户菜单拦截器
 * Created by zhangzhenbin on 17-2-28.
 */
public class WebFrameworkMenuInterceptor extends FrameworkBaseController implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        UserLoginVo currentUser = getCurrentUser(httpServletRequest);
        if(currentUser!= null && modelAndView != null){
            SysMenuTreeVO menuVO = currentUser.getSysMenuTreeVO();
            modelAndView.addObject("menuVO",menuVO);
            modelAndView.addObject("currentUser",currentUser);
        }

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
